import moment from 'moment';

/**
 * 接收参数的时间过滤器 |
 */
moment.locale('zh-cn')

export default function (value, ...rest) {
    const date = value

    if (moment(date).isValid()) {
        // 移除数组中的第一个元素并返回
        const key = rest.shift()

        if (typeof key === 'string') {
            switch (key) {
                case 'from':
                    value = moment(date).from()
                    var otherOpts = rest.shift()
                    if (otherOpts && typeof otherOpts === 'object') {
                        value = moment(date).startOf(otherOpts.startOf).from()
                    }
                    break;
                default:
                    value = moment(date).format(key)
            }
        }
    }
    return value
}